﻿<%@ Page Title="Gửi tin SMS" Language="C#" MasterPageFile="~/App_MasterPages/Aquarius.Master"
    AutoEventWireup="true" CodeBehind="SentSMS.aspx.cs" Inherits="PanasonicWarranty.UI.SentSMS" %>

<%@ Register Src="../UserControl/ucPaging.ascx" TagName="ucPaging" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="CssContent" runat="server">
    <link href="../css/uploadify.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        label{display: inline-block;font-size: 12px;}
        td span{ display: block;}
        #td_message span{display: inline;}
        label input[type=text]{color: #333333;font-size: 11px;line-height: 16px;margin: 0;padding: 3px 2px 3px 5px;
            width: 110px;height: auto;background-color: #FFFFFF;border: 1px solid #CCCCCC;display: inline-block;
            border-radius: 3px 3px 3px 3px;font-family: "Helvetica Neue" ,Helvetica,Arial,sans-serif;vertical-align: middle;}
        .custom-combobox-input{width: 120px !important;}
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ScriptContent" runat="server">
    <script src="../js/jquery.uploadify.js" type="text/javascript"></script>
    <script type="text/javascript">
        function CheckFullInfo() {
            if ($("[id$=txtMessage]").val().length == 0) {
                jAlert('Tin nhắn không được để trống');
                return false;
            }
            if (parseInt($("#lbmessage").html()) > 3) {
                jAlert('Số bản tin không được phép quá 3 tin nhắn trong một lần gửi');
                return false;
            }
            if (CountInvalidPhone($("[id$=txtPhoneList]").val()) == true)
                return confirm("Xác nhận gửi tin nhắn!");
            return false;
        }

        function Authorize() {
            var retvalue = false;
            $.ajax({
                type: "POST",
                url: '<%=ResolveUrl("~/WebService.asmx/Authorize")%>',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: false,
                success: function (data) {
                    retvalue = data.d;
                    if (retvalue == false)
                        jAlert("Bạn không được quyền import file");
                }
            });
            return retvalue;
        }

        function CountInvalidPhone(strPhone) {
            var retvalue = true;
            $.ajax({
                type: "POST",
                url: 'SentSMS.aspx/CountInvalidPhone',
                data: "{'strPhone':" + JSON.stringify(strPhone) + " }",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: false,
                success: function (data) {
                    var totalPhone = parseInt(data.d.TotalPhone);
                    var invalidPhone = parseInt(data.d.InvalidPhone);
                    if (invalidPhone > 0) {
                        retvalue = confirm("Có " + invalidPhone + "/" + totalPhone + " số điện thoại không hợp lệ, bạn có muốn tiếp tục gửi tin nhắn không?");
                    }
                },
                error: function () {
                    alert('Có lỗi xảy ra khi gửi tin nhắn. Vui lòng kiểm tra lại hoặc liên hệ với admin');
                }
            });
            return retvalue;
        }

        $(document).ready(function () {
            RegisterDialog();
            DatePicker("txtFromDate,txtToDate");
            $("[id$=txtMessage]").bind('textchange', function () {
                ShowCount($(this));
            });
            $("[id$='fuImport']").fileUpload({
                'uploader': '../js/uploader.swf',
                'cancelImg': '../img/cancel.png',
                'buttonText': 'Browse Files',
                'script': '../Handler/UpLoad4.ashx',
                'fileDesc': 'Excel file',
                'fileExt': '*.xls;*.xlsx;',
                'multi': false,
                'auto': false,
                'onComplete': function (file, data, response, c) {
                    if (c == "ERROR!") {
                        $("#spUploadResult").html('Có lỗi xảy ra khi import dữ liệu!');
                    }
                    else {
                        var text = $.trim($("[id$='txtPhoneList']").val())
                        if (text != "")
                            $("[id$='txtPhoneList']").val(text + "," + c);
                        else
                            $("[id$='txtPhoneList']").val(c);
                    }
                }
            });
        });
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <div class="row-fluid">
        <div class="span4" style="width: 27%">
            <div class="head">
                <div class="isw-list">
                </div>
                <h1>
                    Nội dung tin nhắn
                </h1>
                <div class="clear">
                </div>
            </div>
            <div class="block-fluid ui-widget ui-widget-content ui-corner-all" style="padding: 10px;
                overflow: auto">
                <div style="width: 100%">
                    <table cellpadding="0" cellspacing="0" width="100%">
                        <tr>
                            <td>Sender name</td>
                            <td><asp:DropDownList ID="ddlShorCode" runat="server" /></td>
                        </tr>
                        <tr>
                            <td>Tin nhắn</td>
                            <td>
                                <asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" Rows="20" Style="width: 206px;
                                    max-width: 206px" />
                            </td>
                        </tr>
                        <tr>
                            <td align="right" colspan="2" id="td_message">
                                <span style="float: left;"><span id="lbletter">0</span> kí tự / <span id="lbmessage">1</span> tin nhắn </span>
                                <asp:Button ID="btnSentMessage" runat="server" Text="Send" OnClick="btnSentMessage_Click"
                                    OnClientClick="return CheckFullInfo();" CssClass="btn" />
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        <div class="span8" style="margin-left: 1%; width: 72%;">
            <div class="head">
                <div class="isw-list">
                </div>
                <h1>
                    Danh sách khách hàng</h1>
                <ul class="buttons">
                    <li>
                        <asp:LinkButton CssClass="isw-download" ID="btnDownload" runat="server" ToolTip="Download mẫu file import danh sách"
                            OnClick="btnDownload_Click" /></li>
                    <li>
                        <asp:LinkButton CssClass="isw-attachment" ID="btnUpload" runat="server" ToolTip="Import danh sách số điện thoại"
                            OnClientClick="$('#spUploadResult').html(''); return OpenDialog('dialog2',400);" /></li>
                </ul>
                <div class="clear">
                </div>
            </div>
            <div class="block-fluid  ui-widget ui-widget-content ui-corner-all">
                <table border="0" width="100%">
                    <tr>
                        <td colspan="2">
                            <asp:TextBox ID="txtPhoneList" runat="server" TextMode="MultiLine" Rows="24" Style="width: 777px;
                                max-width: 777px" onkeypress="return ValidateKeypress(/[\d\,]+/,event);" />
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    <div class="dialog" id="dialog1" title="Lựa chọn danh sách số điện thoại" style="display: none;">
        <asp:Panel ID="pnl_dialog1" runat="server" CssClass="block">
            <div>
                <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <td style="width: 140px">Nhóm khách hàng</td>
                        <td><asp:DropDownList ID="ddlCustomerGroup" runat="server" /></td>
                    </tr>
                </table>
            </div>
            <div class="dr">
                <span></span>
            </div>
            <div style="text-align: right">
                <asp:Button ID="btnOk" runat="server" Text="OK" CssClass="btn" OnClick="btnOk_Click" />
                <input type="button" class="btn" value="Cancel" onclick="$('#dialog1').dialog('close'); return false;" />
            </div>
        </asp:Panel>
    </div>
    <div class="dialog" id="dialog2" title="Lựa chọn file Import" style="display: none;">
        <asp:Panel ID="pnl_dialog2" runat="server" CssClass="block">
            <div>
                <asp:FileUpload ID="fuImport" runat="server" />
            </div>
            <div style="text-align:center; color:Red">
                <span id="spUploadResult"></span>
            </div>
            <div class="dr"><span></span></div>
            <div style="text-align: right">
                <input type="button" class="btn" value="Import" onclick='$("[id$=fuImport]").fileUploadStart();' />
                <asp:Button ID="btnCancel" CssClass="btn" Text="Đóng" runat="server" OnClientClick="$('[id$=fuImport]').fileUploadClearQueue(); $('#dialog2').dialog('close'); return false;" />
            </div>
        </asp:Panel>
    </div>
</asp:Content>
